/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TipoConceptoGUI.java
 *
 * Created on 13-mar-2012, 17:42:37
 */

package VISTA;
import MODELO.*;
import CONTROL.*;
/**
 *
 * @author Wilfredo
 */
public class TipoConceptoGUI extends javax.swing.JDialog {

    /** Creates new form TipoConceptoGUI */
    public TipoConceptoGUI(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        TransBDTipoConcepto.consultarTodos();
        if(ServicioBD.siguiente()){
            TipoConcepto x=TransBDTipoConcepto.get();
             muevaloalaventana(x);
        }
        else
            System.out.println("OCURRIO ALGO RARO NO ESPERADO");

    }

    public void muevaloalaventana(TipoConcepto m){

        jTextField1.setText(m.getTipocodigo());
        jTextField2.setText(m.getDescripcion());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("TIPO");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(29, 41, -1, -1));
        jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(71, 38, 242, -1));
        jPanel1.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(125, 102, 188, -1));

        jLabel2.setText("DESCRIPCION");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(29, 105, -1, -1));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/35.png"))); // NOI18N
        jButton1.setText("Regresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(630, 480, 130, 40));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 80, 790, 550));

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/13.png"))); // NOI18N
        jButton2.setText("Adicionar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 110, 50));

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/44.png"))); // NOI18N
        jButton3.setText("Modificar");
        jPanel2.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 10, 120, 50));

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Borrar.png"))); // NOI18N
        jButton4.setText("Borrar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 10, 130, 50));

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/42.png"))); // NOI18N
        jButton5.setText("Buscar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 10, 140, 50));

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1010, 80));

        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/primeroimag1.jpg"))); // NOI18N
        jButton6.setToolTipText("Primero");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 30, 100, 40));

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/siguiente2.jpg"))); // NOI18N
        jButton7.setToolTipText("Siguiente");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 80, 100, 40));

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/anterior2.jpg"))); // NOI18N
        jButton8.setToolTipText("Anterior");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 130, 100, 40));

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/ultimoimag2.jpg"))); // NOI18N
        jButton9.setToolTipText("Ultimo");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 180, 100, 40));

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 80, 220, 550));

        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setText("GESTION DE INFORMACION TIPO CONCEPTO");
        jPanel4.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

        getContentPane().add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 630, 1010, 40));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        String codigo = jTextField1.getText();
        String descripcion  = jTextField2.getText();
        TipoConcepto pa=new TipoConcepto(codigo,descripcion);
        if(TransBDTipoConcepto.buscar(codigo)){
           javax.swing.JOptionPane.showMessageDialog(this, "TIPO CONCEPTO YA EXISTE");
           return;
        }
        if(TransBDTipoConcepto.adicionar(pa))
         javax.swing.JOptionPane.showMessageDialog(this, "TIPO CONCEPTO INGRESADO EXITOSAMENTE");
        else
           javax.swing.JOptionPane.showMessageDialog(this, "TIPO CONCEPTO NO SE PUDO ADICIONAR");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        String codigo = jTextField1.getText();
     if (TransBDTipoConcepto.buscar(codigo)){
         TransBDTipoConcepto.borrar(codigo);
         System.out.println("ESTO FUNIONA POR AQUI BIEN PORQUE LO ENCONTRO");
     }
     else
           javax.swing.JOptionPane.showMessageDialog(this, "NO EXISTE PARA BORRARLO");
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
         String codigo = jTextField1.getText();
  if (TransBDTipoConcepto.buscar(codigo)){
       TipoConcepto x= TransBDTipoConcepto.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO LO ENCONTRO");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO LO ENCONTRO");
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        if (ServicioBD.primero()){
       TipoConcepto x= TransBDTipoConcepto.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
        if (ServicioBD.siguiente()){
       TipoConcepto x= TransBDTipoConcepto.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
       muevaloalaventana(x);
}
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here:
        if (ServicioBD.anterior()){
       TipoConcepto x= TransBDTipoConcepto.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        // TODO add your handling code here:
        if (ServicioBD.ultimo()){
       TipoConcepto x= TransBDTipoConcepto.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                TipoConceptoGUI dialog = new TipoConceptoGUI(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables

}
